package com.zetyun.tiger.format.filter;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.meta.jsonschema.annotation.JsonSchemaTitle;
import com.zetyun.rt.sdk.action.FilterAction;
import com.zetyun.rt.sdk.model.RtEvent;
import com.zetyun.rt.sdk.operator.OperatorContext;

import java.util.Objects;

//@ActionMeta(
//        id = "tiger.filter-by-tb-name",
//        tags = {"Header"},
//        category = "filter",
//        name = "FilterByTbNameAction",
//        parameterClass = FilterByTbNameParameter.class,
//        description = "根据特定规则组装Sink主题信息"
//)
public class FilterByTbNameAction extends FilterAction {


    private String headerField;

    private String headerFieldValue;

    @Override
    public void init(OperatorContext context) {
        super.init(context);
        FilterByTbNameParameter parameters = context.getParameters();

        headerField = parameters.getHeaderField();
        headerFieldValue = parameters.getHeaderFieldValue();
    }

    @Override
    public boolean apply(RtEvent rtEvent) throws Exception {

        Object headerObj = rtEvent.getHeader(headerField);

        if (Objects.nonNull(headerObj)) {

            return headerFieldValue.equals(headerObj);
        }

        return false;
    }
}
